﻿using System.Windows;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.UnityExtensions;
using Client2.Dialog;
using Client2.Classes;

namespace Client2
{
    public class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return this.Container.Resolve<Shell>();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();

            Auth dialog = new Auth();
            bool? result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                ConfigStorage.CurrentUser = dialog.User;

                App.Current.MainWindow = (Window)this.Shell;
                App.Current.MainWindow.Show();
            }
            else
            {
                Application.Current.Shutdown();
            }

        }

        protected override void ConfigureModuleCatalog()
        {
            base.ConfigureModuleCatalog();

            ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
            moduleCatalog.AddModule(typeof(DesktopModule.Product.DesktopModuleProduct));
        }
    }
}
